﻿@using Microsoft.JSInterop
@inject IJSRuntime JSRuntime
@implements IDisposable

<noscript><strong>We're sorry but CareAtHome doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript>
<div id="app"></div>

@code {
    [JSInvokable]
    public static Task<string> GetFoo()
    {
        return Task.FromResult("this is a foo call from c# method from js");
    }

    [JSInvokable]
    public static Task<int> Add(AddInput addInput)
    {
        return Task.FromResult(addInput.a + addInput.b);
    }

    public async void Post(object o, EventArgs e)
    {
        await JSRuntime.InvokeAsync<string>("postBar", "this is bar call js method from C#");
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        ((App.Current as App).MainPage as MainPage).OnPostBar += Post;
        try
        {
            if (firstRender)
            {
                await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./asserts/vendor.bc13e36d.js", new { crossorigin = "anonymous" });
                await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./asserts/index.e82d8ae2.js", new { crossorigin = "anonymous" });
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }

    public void Dispose()
    {
        (Application.Current.MainPage as MainPage).OnPostBar -= Post;
    }
}
